/**
 * speed
 * @author 
 * 2016/5/27
 */
class GameDict {
    private dict:any = {};
    private keyArr:Array<string> = [];
	private _length:number = 0;
	
	public constructor() {
	}
	
	public put(key:any,value:any):void{
		var self = this;
        if(self.dict[key])
		{
			if(value == null)
			{
    			var index = self.keyArr.indexOf(key);
    			self.keyArr.splice(index,1);
                delete self.dict[key];
				self._length--;
			}else
			{
    			if(self.keyArr.indexOf(key) == -1){
                    self.keyArr.push(key);
    			}
			    self.dict[key] = value;
			}
		}
		else
		{
			if(value != null)
			{
                if(self.keyArr.indexOf(key) == -1) {
                    self.keyArr.push(key);
                }
				self.dict[key] = value;
				self._length++;
			}			
		}		
	}
	
	public shift():any{
	    var self = this;
	    if(self.keyArr && self.keyArr.length){
            var key: string = self.keyArr[0];
            var value:any = self.get(key);
            self.despose(value);
            self.put(key,null);
            return value;
	    }
	    return null;
	}
	
	public indexOf(index):any{
        var self = this;
        if(self.keyArr && self.keyArr.length) {
            var key: string = self.keyArr[index];
            var value: any = self.get(key);
            return value;
        }
        return null;
	}
	
	private despose(value:any):void{
        var self = this;
        if(value){
            if(value instanceof data.SoundInfo){
                (<data.SoundInfo>value).despose();
            }
        }
	}
	
    public hasOwnProperty(pro:string):boolean{
        return this.dict.hasOwnProperty(pro);
	}
		
	public get(key:any):any
	{
		return this.dict[key];
	}
		
	public get length():number
	{
		return this._length;
	}
	
	public get data():any
	{
		return this.dict;
	}
		
	public clear():void
	{
		for(var key in  this.dict)
		{
			delete this.dict[key];
		}
		if(this.keyArr){
            this.keyArr.splice(0,this.keyArr.length)
		}
		this._length = 0;
	}
}
